﻿using JunionRobotTaskManager.Repository;
using SqlSugar;

namespace JunionRobotTaskManager.Models
{
    /// <summary>
    /// 充电点
    /// </summary>
    public class Dock
    {


        /// <summary>
        /// 充电的Id即充电路径
        /// </summary>
        [SugarColumn(IsPrimaryKey = true)]
        public string Id { get; set; }

        /// <summary>
        /// 是否启用
        /// </summary>
        public bool Enable { get; set; } = true;

        /// <summary>
        /// 是否占用
        /// </summary>
        public bool IsOccupied { get; set; }

        /// <summary>
        /// 所在区域
        /// </summary>
        public string Region { get; set; }

        /// <summary>
        /// X坐标
        /// </summary>
        public float XPosition { get; set; }  //X坐标

        /// <summary>
        /// Y坐标
        /// </summary>
        public float YPosition { get; set; } //Y坐标

        /// <summary>
        ///当前占用的机器人Id
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public string RobotId { get; set; }

        /// <summary>
        /// 所在楼层
        /// </summary>
        public int Floor { get; set; }

        #region Method

        /// <summary>
        /// 重置Dock点
        /// </summary>
        /// <param name="dockRepository"></param>
        /// <returns></returns>
        public bool ReSetDock(IDockRepository dockRepository)
        {
            IsOccupied = false;
            RobotId = null;
            return dockRepository.UpdateEntity(this);
        }

        /// <summary>
        /// 设置
        /// </summary>
        /// <param name="dockRepository"></param>
        /// <returns></returns>
        public bool SetDock(IDockRepository dockRepository,string robotId )
        {
            RobotId = robotId;
            return dockRepository.UpdateEntity(this);
        }
        #endregion


        #region 重写Equal
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return false;
            }
            if (ReferenceEquals(obj, this))
            {
                return true;
            }
            if (obj.GetType() != GetType())
            {
                return false;
            }
            return obj is Dock b && Id == (obj as Dock).Id;
        }

        public override int GetHashCode()
        {
            return Id.GetHashCode();
        }
        #endregion
    }
}
